(function($){

	//用户信息下拉菜单
	var timeout = 500;
	var closetimer = 0;
	var ddmenuitem = 0;

	function userName_close(){
		if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	}

	$('#Jnav > li').bind('mouseover', function(){
		if(closetimer){
			window.clearTimeout(closetimer);
			closetimer = null;
		}
		userName_close();
		ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
		$(".arrowDown").addClass("arrowUp");
	}).bind('mouseout', function(){
		closetimer = window.setTimeout(userName_close, timeout);
	});

	//定制
	$(".specific li").mouseenter(function(){
		var index = $(this).index();
		//alert(index)
		$(".customMade").eq(index).show().siblings(".customMade").hide();
	});
	
	//获取验证码倒计时特效
	$("#getCode1").click(function(){
		var second = 59,
			_this = $(this);
		_this.css({"color":"#ccc"});
		_this.attr("value","等待60秒");
		_this.attr("disabled", "disabled");
		var si = setInterval(function(){
			_this.attr("value","等待"+second+"秒");
			second--;
			if( second == -2 ){
				clearInterval(si);
				_this.attr("value","获取验证码");
				_this.css({"color":"#37005a"});
				_this.removeAttr("disabled")
			}
		},1000)
	});
	
	$("#getCode2").click(function(){
		var second = 59,
			_this = $(this);
		_this.css({"color":"#ccc"});
		_this.attr("value","等待60秒");
		_this.attr("disabled", "disabled");
		var si = setInterval(function(){
			_this.attr("value","等待"+second+"秒");
			second--;
			if( second == -2 ){
				clearInterval(si);
				_this.attr("value","获取验证码");
				_this.css({"color":"#37005a"});
				_this.removeAttr("disabled")
			}
		},1000)
	});
	
	$("#getCode3").click(function(){
		var second = 59,
			_this = $(this);
		_this.css({"color":"#ccc"});
		_this.attr("value","等待60秒");
		_this.attr("disabled", "disabled");
		var si = setInterval(function(){
			_this.attr("value","等待"+second+"秒");
			second--;
			if( second == -2 ){
				clearInterval(si);
				_this.attr("value","获取验证码");
				_this.css({"color":"#37005a"});
				_this.removeAttr("disabled")
			}
		},1000)
	});
	
	$("#getCode4").click(function(){
		var second = 59,
			_this = $(this);
		_this.css({"color":"#ccc"});
		_this.attr("value","等待60秒");
		_this.attr("disabled", "disabled");
		var si = setInterval(function(){
			_this.attr("value","等待"+second+"秒");
			second--;
			if( second == -2 ){
				clearInterval(si);
				_this.attr("value","获取验证码");
				_this.css({"color":"#37005a"});
				_this.removeAttr("disabled")
			}
		},1000)
	});
	
	//信息确认弹出层
	$(".confirm").live('click',function(){
		$.blockUI({
			message : $('.confirmDiv'),
			css : {
				background : "none",
				border : "none",
				width:590,
				height:424,
				top : ($(window).height()-424)/2 + "px",
				left : ($(window).width()-590)/2 + "px"
			},
			overlayCSS : { 
				backgroundColor : '#000', 
				opacity : 0.6
			},
			onBlock:function(){
				$(".closeConfirm").click(function(){
					$.unblockUI(); 
                    return false;
				});
			}
		});
	});
	
	
	
	

})(jQuery);

if($.validator) {
	
	$.validator.addMethod("IDCheck", 
		function(value, element, param) {
			var idCard = value;
			if(idCard) {
				var checkFlag = new clsIDCard(idCard);
				return checkFlag.IsValid();
			}
			return true;
		}, 
	"身份证号不对");
	
	$.validator.setDefaults({
		highlight: function(element, errorClass) {
			$(element).css("border-color", "red");
		},
		unhighlight: function(element, errorClass) {
			$(element).css("border-color", "#fff");
		},
		errorPlacement:  function(error, element) {
			
		 },
		errorClass: "myValidateError"
	});
}


function checkPhoneNum() {
	var inputPhoneNum = $("#phoneNum").val();
	if(inputPhoneNum.trim()=="") {
		 alert("手机号为空");
		 return false;
 	} else {
 		if(typeof(inputPhoneNum)=="undefined") {
 			return false;
 		}
		
		if(inputPhoneNum.trim().length!=11){
			 alert("请输入11位手机号码");
			 return false;
		}
		
		var myreg = /^(1[3-9]{1}[0-9]{1})\d{8}$/;
		if(!myreg.test(inputPhoneNum)){
			 alert("请输入合法的手机号码！");
		return false;
		}
		 return true;
 	}
	
}

  function check(){
    	 var peopleName = $("#peopleName").val();
		 var address = $("#address").val(); 
    	 var zipCode = $("#zipCode").val(); 
    	 var email = $("#win_info_email").val(); 
    	 
    	 if (peopleName == "") {
    		 alert("收货人为空");
    		 return false;
    	 }
    	 if (address == "") {
    		 alert("地址为空");
    		 return false;
    	 }
    	 if (email == "") {
    		 alert("邮箱为空");
    		 return false;
    	 }
    	 return true;
     }



//抽奖成功弹出层
function prizeSuccess(target){
	$.blockUI({
		message : $('.prizeSuccessDiv'),
		css : {
			background : "none",
			border : "none",
			width:590,
			height:424,
			top : ($(window).height()-424)/2 + "px",
			left : ($(window).width()-590)/2 + "px"
		},
		overlayCSS : { 
			backgroundColor : '#000', 
			opacity : 0.1
		},
		showOverlay: false,
		onBlock:function(){
			$(".closeConfirm").click(function(){
				$.unblockUI(); 
				target.find("div").hide();
				return false;
			});
			$(".sure").click(function(){
				var form = $("#saveWinPeopInfo_form");
				var result = check();
				
				var result2 =checkPhoneNum();
				
				if (result && result2) {
					$.ajax({
						url: "saveWinPeopInfo.jhtml",
						type: "post",
						data: form.serialize(),
						dataType: "json",
						cache: false,
						async: false,
						beforeSend: function() {
							
						},
						success: function(message) {
							if (message == "false") {
								alert("对不起，提交数据失败，请重新提交中奖信息！");
							} else {
								$.unblockUI();
								alert("您已经提交中奖信息，请等待我们的联系！");
							}
						}
					});
				} else {
					return true;
				}
				target.find("div").hide();
				return false;
			});
			//$(".sure").unbind('click');
			//$(".sure").bind('click');
		}
	});
};


//抽奖失败弹出层
function prizeFail(target){
	$.blockUI({
		message : $('.prizeFailDiv'),
		css : {
			background : "none",
			border : "none",
			width:590,
			height:160,
			top : ($(window).height()-160)/2 + "px",
			left : ($(window).width()-590)/2 + "px"
		},
		overlayCSS : { 
			backgroundColor : '#000', 
			opacity : 0.6
		},
		showOverlay: false,
		onBlock:function(){
			$(".closeConfirm").click(function(){
				$.unblockUI();
				target.find("div").hide();
				return false;
			});
		}
	});
};

